﻿using System;

namespace Caculator1._0
{
    class Program
    {
        static void Main(string[] args)
        {
            int num1 = 0; int num2 = 0;

            Console.WriteLine("C# caculator:");

            try
            {
                Console.WriteLine("请输入第一个整数：");
                num1 = Convert.ToInt32(Console.ReadLine());


                Console.WriteLine("请输入第二个整数：");
                num2 = Convert.ToInt32(Console.ReadLine());


                Console.WriteLine("选择你要进行的操作:");



                switch (Console.ReadLine())
                {
                    case "+":
                        Console.WriteLine($"结果为: {num1} + {num2} = " + (num1 + num2));
                        break;
                    case "-":
                        Console.WriteLine($"结果为: {num1} - {num2} = " + (num1 - num2));
                        break;
                    case "*":
                        Console.WriteLine($"结果为: {num1} * {num2} = " + (num1 * num2));
                        break;
                    case "/":
                        while (num2 == 0)
                        {
                            Console.WriteLine("请输入非零整数作为被除数: ");
                            num2 = Convert.ToInt32(Console.ReadLine());
                        }
                        Console.WriteLine($"结果为: {num1} / {num2} = " + (num1 / num2));
                        break;
                }
            }
            catch (FormatException)
            {
                Console.WriteLine("Input format is error!");
                return;
            }
            catch (OverflowException)
            {
                Console.WriteLine("Inputted number is overflow!");
                return;
            }
            Console.Write("计算完成");
            Console.ReadKey();
        }
    }
}
